<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<% Option explicit %>
<html><!-- InstanceBegin template="/Templates/common.dwt" codeOutsideHTMLIsLocked="false" -->
<!--#include virtual="/timereport/include/auth.asp" -->
<!--#include virtual="/timereport/include/common.asp" -->

<head>
<!-- InstanceBeginEditable name="doctitle" --> 
<title>Report spese</title>
<!-- InstanceEndEditable --> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --> 
<link href="../include/commoncss.asp" rel="stylesheet" type="text/css">
<%
'	No authorization for this function
	If Session("userLevel") < 1 Then 
		response.redirect("../menu.aspx?msgtype=E&msgno=" & MSGNO_AUTHORIZATION_FAILED)
	End if	
	
	Sub Scrivi_Tabella( titolo, condizione)
		Dim i
		Dim totale
			
		%>		
		<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
		<tr><td class=tabellabianca><b> <%=titolo %> </b></td></tr>
		</table>
			
		<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" class="TabellaReport">
		<tr>
		<th>Data</th>
		<th>Codice spesa</th>
		<th>Descrizione</th>
		<th>Importo</th>
		<th>Um</th>
		<th>Totale Euro</th>
		<th>Nota</th>		
		</tr>
		<%
							
		totale = 0							
								
		' cicla sui record estratti
		For i=0 to Ubound(aExpenses, 2) 
			' in base alla condizione stampa o meno la spesa
			If aExpenses(0, i) = condizione Then
				%>
				<tr>
				<td><%=aExpenses(1,i)%> &nbsp;</td> <!-- Data -->
				<td><%=aExpenses(2,i)%> &nbsp;</td> <!-- Codice spesa -->
				<td nowrap><%=aExpenses(3,i)%> &nbsp;</td> <!-- Descrizione -->
				<td align=Right><%=aExpenses(4,i)%> &nbsp;</td> <!-- Importo -->
				<td align=Right><%=aExpenses(5,i)%> &nbsp;</td> <!-- Um -->
				<td align=Right><%=aExpenses(6,i)%> &nbsp;</td> <!-- Totale Euro -->
				<td><%=aExpenses(7,i)%> &nbsp;</td> <!-- Nota -->							
				</tr>
				<%			
				totale = totale + aExpenses(6,i)

			End If	
		Next
			
		' scrive totale
		%>

		<tr>
		<th align=Left colspan=5> Totale </th>
		<th align=Right><%=FormatNumber(totale, 2, false) %> </th>
		<th>&nbsp;</th>		
		</tr>

		</table>			

		<br><br>
		<%		
	
	End Sub
	
%>

<!-- InstanceEndEditable -->
</head>

<SCRIPT language=JavaScript src= "/timereport/include/menu/menu_array.js" type=text/javascript></SCRIPT>
<SCRIPT language=JavaScript src= "/timereport/include/menu/mmenu.js" type=text/javascript></SCRIPT>

<body>
<table width="760" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr> 
    <td height="30" class="BarraTop"><div align="right">Utente: <%= session("UserName") %> 
      </div></td>
  </tr>
  <tr>
    <td height="30">&nbsp;</td>
  </tr>
  <tr> <!-- InstanceBeginEditable name="principale" --> 
    <td > 
      <% if request.form("submit") = "" then %>
      <form name="form1" method="post" action="report-spese-dettaglio.asp">
        <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0" class="BoxDialogo">
          <tr> 
            <th colspan="2">Criteri di selezione</th>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td width="30%">Mese:</td>
            <td> 
				<select name="Month" class="FormInput">
				<% call SelectMonths() %>
				</select>
			</td>
          </tr>
          <tr> 
            <td>Anno:</td>
            <td> <select name="Year" class="FormInput">
				<% call SelectYears() %>
              </select></td>
          </tr>
          <tr> 
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
        </table>
        <br>
        <table width="60%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr> 
            <td><input name="Submit" type="submit" class="FormButtont" value="Esegui"></td>
          </tr>
        </table>
       </form>
      
	  <% else 
	  
		' array che contiene tutti i record estratti
		Dim aExpenses, f
		
		Dim sBeginDate, sEndDate
	
		' Seleziona le persone attive e le mette nell'array aPerson
		call MakeConn(objConn,DATABASE)
		Call PrepareQuery(objConn, "QueryDettaglioSpese")

		objCmd.Parameters.Append  _
				objCmd.CreateParameter ("persona",adInteger, adParamInput )
		objCmd.Parameters.Append _
				objCmd.CreateParameter  ("startdate",adVarChar, adParamInput ,10)
' ACCES  objCmd.CreateParameter  ("startdate",adDate, adParamInput )
		objCmd.Parameters.Append _ 
				objCmd.CreateParameter    ("enddate",adVarChar, adParamInput ,10)
' Access objCmd.CreateParameter  ("enddate",adDate, adParamInput )	

		sBeginDate = FirstDay( request("month"), request("year") )  
		sEndDate = LastDay( request("month"), request("year") )  

		Call CaricaParametroQuery("persona", Session("persons_id") )

'		 Access
'       objCmd("enddate") = cdate(sEndDate)
'		objCmd("startdate") = cdate(sBeginDate)		
				
'		MSSQL
	    objCmd("startdate") = Month(sBeginDate) & "-" & Day(sBeginDate) & "-" &  Year (sBeginDate)
		objCmd("enddate") =  Month(sEndDate) & "-" &  Day(sEndDate)& "-" &  Year (sEndDate)

		Set objRS = objCmd.Execute 
		
		if objRs.EOF = true then
	'		nessun record trovato
			response.Write("Nessun record trovato")		
			destroy(objRs)
			destroy(objConn)
		else
		
'			carica record in tabella
			aExpenses= objRs.getrows            		
						
			destroy(objRs)
			destroy(objConn)
			
'		Scrive i record trovati			
			
			Call scrivi_tabella("Spese pagate azienda", true)			
			Call scrivi_tabella("Spese con pagamento personale", false)
					
		End if	
		
		End if		
	%>
	
	  
	  </td>
    <!-- InstanceEndEditable --></tr>
</table>
</body>
<!-- InstanceEnd --></html>
